package manager
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.external.ExternalInterface;
	import flash.system.Security;
	
	
	/**
	 * 
	 * @author Kbin
	 * 
	 */
	public class ExternalInterfaceManager extends EventDispatcher
	{
		public static const SOUND_ON:String = "SOUND_ON";
		public static const SOUND_OFF:String = "SOUND_OFF";
		
		private static var _instance : ExternalInterfaceManager;
		public static function get instance():ExternalInterfaceManager
		{
			if(!_instance) _instance = new ExternalInterfaceManager();
			return _instance;
		}
		
		public function ExternalInterfaceManager()
		{
		}
		
		public function setup():void
		{
			if(ExternalInterface.available)
			{
				ExternalInterface.addCallback("SetSoundOff",SetSoundOff);
				ExternalInterface.addCallback("SetSoundOn",SetSoundOn);
				ExternalInterface.addCallback("PopSetPanel",PopSetPanel);
			}
		}
		
///////////////////////////////////////////////////////////////////////////  注册接口
		/**
		 * 打开flash设置面板
		 */		
		private function PopSetPanel():void
		{
			flash.system.Security.showSettings();
		}
		
		/**
		 * 关闭声音
		 */		
		private function SetSoundOff():void
		{
			dispatchEvent(new Event(SOUND_OFF));
		}
		
		/**
		 * 开启声音
		 */		
		private function SetSoundOn():void
		{
			dispatchEvent(new Event(SOUND_ON));
		}
		
///////////////////////////////////////////////////////////////////  调用外部接口
		/**
		 *同步登陆器显示时间 
		 * @param totalSeconds  当天总秒数
		 */		
		public function syncDesktopTime(totalSeconds:Number):void
		{
			if(ExternalInterface.available)
				ExternalInterface.call("SyncDesktopTimer",String(totalSeconds));
		}
		
	}
}